package com.frank.oj.controller.file;

import com.frank.oj.common.result.CommonResult;
import com.frank.oj.service.file.ProblemFileService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author frank
 * @Date 2024/4/5
 */
@RestController
@RequiresRoles("root")
@RequiresAuthentication
@RequestMapping("/api/file")
public class ImportProblemFileController {
    @Resource
    private ProblemFileService problemFileService;

    /**
     * 导入zip文件格式的题目
     *
     * @param file 文件
     * @return null
     */
    @PostMapping("/import-problem")
    public CommonResult<Void> importProblem(@RequestParam("file") MultipartFile file) {
        return problemFileService.importProblem(file);
    }

    @GetMapping("/export-problem")
    public void exportProblem(@RequestParam("pid") List<Long> pidList, HttpServletResponse response) {
        problemFileService.exportProblem(pidList, response);
    }
}
